<template>
  <div class="m-home">
    <!-- 头部背景图 -->
    <div class="page-top">
      <img class="home-bg" src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/home-bg.png" :alt="`${$t('platform')}`" />
      <div class="bg-desc">
        <div class="desc-item">
          <p>{{ $t("platform") }}</p>
          <span>{{ $t("platformDescription") }}</span>
        </div>
        <a class="desc-btn" href="/m-about-us" :title="`${$t('aboutYunlian')}`">
          <span>{{ $t("learnMore") }}</span>
          <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/right-small-white.png" />
        </a>
      </div>
    </div>
    <!-- 设备分类 -->
    <div class="view-title m-container">{{ $t("equipmentCategorization") }}</div>
    <div class="equipment-assort m-container">
      <a
        class="assort-item"
        :href="`/m-used-machine/${item.titleEn}-${item.id}`"
        :title="`${$t('categorizationDetail')[index]} ${$t('machines')}`"
        v-for="(item, index) in assortList"
        :key="item.title"
      >
        <img :src="item.img" :alt="`${$t('categorizationDetail')[index]}`" />
        <span>{{ $t("categorizationDetail")[index] }}</span>
      </a>
    </div>
    <!-- 热卖机型 -->
    <div class="view-title m-container" v-if="equipmentList.length">{{ $t("hotSellingModels") }}</div>
    <section class="equipment-list m-container" v-if="equipmentList.length">
      <a
        class="equipment-item"
        v-for="item in equipmentList"
        :key="item.crmEquipmentId"
        :href="`/m-equipment/${item.typeNameEn}-${item.crmEquipmentId}`"
        :title="`${item.title} | ${item.subHeading}`"
      >
        <el-image class="info-img" fit="cover" :src="item.thumbnail" lazy :alt="item.title"></el-image>
        <div class="info-bottom">
          <div class="info-title">{{ item.title }}</div>
          <div class="info-year">{{ item.subHeading }}</div>
          <div class="info-tag" v-if="locale == 'zh-CN'">
            <p v-for="val in item.targerList" :key="val">{{ val }}</p>
          </div>
          <div style="height: 18px" v-else></div>
          <div class="info-price">
            <template v-if="item.crmEquipmentFixedPriceId && item.offlineBargaining != 1">
              <p v-if="locale == 'en-US'">CNY{{ item.startingPriceNotag }}</p>
              <p v-else>{{ item.startingPrice / 1000000 }}万</p>
            </template>
            <p v-else>{{ $t("priceNegotiable") }}</p>
          </div>
        </div>
      </a>
    </section>
    <!-- 查看更多 -->
    <a class="check-more" href="/m-used-machine/excavator-47" :title="`${$t('yunLianUsedMachine')}`">
      <span>{{ $t("viewMore") }}</span>
      <img src="https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/right-small-white.png" />
    </a>
    <!-- WhatsApp -->
    <!-- <WhatsAppM v-if="locale == 'en-US'" /> -->
    <!-- 底部信息 -->
    <FooterM></FooterM>
  </div>
</template>

<script>
import { mapState } from "vuex"
import BigNumber from "bignumber.js"
export default {
  name: "M-home",
  layout: "mobile",
  components: {},
  data() {
    return {
      assortList: [
        { id: 54, title: "起重机", titleEn: "Crane", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/crane-1.png" },
        { id: 50, title: "泵车", titleEn: "Pump", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/pump-1.png" },
        { id: 51, title: "车载泵", titleEn: "Vehicle", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/vehicle-1.png" },
        { id: 53, title: "搅拌车", titleEn: "Mixer", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/mixer-1.png" },
        { id: 56, title: "压路机", titleEn: "Rooler", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/rooler.png" },
        { id: 55, title: "旋挖钻", titleEn: "Rotary", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/rotary-1.png" },
        { id: 52, title: "拖泵", titleEn: "Trailer", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/trailer-1.png" },
        { id: 47, title: "挖掘机", titleEn: "Excavator", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/excavator-1.png" },
        { id: 49, title: "装载机", titleEn: "Loader", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/loader-1.png" },
        { id: 57, title: "摊铺机", titleEn: "Paver", img: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/paver.png" }
      ]
    }
  },
  head() {
    return {
      title: this.$i18n.t("headTitle"),
      meta: [
        {
          hid: "keywords",
          name: "keywords",
          content: this.$i18n.t("haeaKeyContent")
        },
        {
          hid: "description",
          name: "description",
          content: this.$i18n.t("haeaDecContent")
        }
      ]
    }
  },
  async asyncData({ app, query }) {
    let equipmentList = [] //设备列表
    try {
      // 热卖机型
      let { data } = await app.$api.equipmentList({ pageNo: 1, pageSize: 8, search: { popular: 1 } })
      equipmentList = (data.list || []).map((item) => {
        item.startingPriceNotag = new BigNumber(item.startingPrice).dividedBy(100).toFormat()
        let targerList = app.$optionsData.parseLabel(item)
        if (targerList.indexOf("寄售") != -1) {
          targerList.splice(targerList.indexOf("寄售"), 1)
        }
        targerList = targerList.splice(0, 2)
        item["targerList"] = targerList
        return item
      })
    } catch (error) {
      console.log(error)
    }
    return {
      equipmentList
    }
  },
  props: {},
  computed: { ...mapState(["locale"]) },
  async mounted() {
    this.getPoint()
  },
  methods: {
    async getPoint() {
      let params = await this.$optionPoint.sendUrl(window, navigator, document)
      this.$api.burySave({ ...params }).then((res) => {})
    }
  },
  watch: {}
}
</script>

<style lang="scss" scoped>
.m-home {
  .page-top {
    width: 100%;
    height: 100%;
    position: relative;
    .home-bg {
      width: 100%;
      height: 1024px;
    }
    .bg-desc {
      width: 100%;
      position: absolute;
      left: 0;
      bottom: 102px;
      display: flex;
      flex-direction: column;
      align-items: center;
      .desc-item {
        width: 95%;
        display: flex;
        flex-direction: column;
        align-items: center;
        p {
          width: 98%;
          font-family: PingFangSC, PingFang SC;
          font-weight: 600;
          font-size: 113px;
          color: #fff;
          line-height: 113px;
          text-align: center;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        span {
          text-align: center;
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 61px;
          color: #fff;
          line-height: 72px;
          margin-top: 26px;
        }
      }
      .desc-btn {
        width: 768px;
        height: 154px;
        background: #d71519;
        margin-top: 51px;
        display: flex;
        align-items: center;
        justify-content: center;
        span {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 61px;
          color: #fff;
        }
        img {
          width: 31px;
          height: 51px;
          margin-left: 10px;
        }
      }
    }
  }
  .view-title {
    font-family: PingFangSC, PingFang SC;
    font-weight: 500;
    font-size: 82px;
    color: #333;
    line-height: 92px;
    margin-top: 102px;
    margin-bottom: 51px;
  }
  .equipment-assort {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .assort-item {
      width: 307px;
      height: 312px;
      position: relative;
      &:nth-child(n + 6) {
        margin-top: 77px;
      }
      img {
        width: 100%;
        height: 100%;
      }
      span {
        width: 100%;
        text-align: center;
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 60px;
        color: #333;
        line-height: 80px;
        position: absolute;
        left: 0;
        bottom: 26px;
      }
    }
  }
  .equipment-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    .equipment-item {
      width: 860px;
      height: 100%;
      margin-bottom: 50px;
      .info-img {
        width: 860px;
        height: 543px;
        display: block;
      }
      .info-bottom {
        width: 100%;
        height: 486px;
        background: #f6f7f9;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 50px;
        box-sizing: border-box;
        .info-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 72px;
          color: #333;
          line-height: 92px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .info-year {
          font-family: PingFangSC, PingFang SC;
          font-weight: 400;
          font-size: 60px;
          color: #999;
          line-height: 80px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .info-tag {
          display: flex;
          align-items: center;
          p {
            height: 60px;
            line-height: 60px;
            padding: 10px;
            border-radius: 12px;
            font-family: PingFangSC, PingFang SC;
            font-weight: 400;
            font-size: 40px;
            color: #fb463f;
            background: rgba(251, 70, 63, 0.08);
            margin-right: 30px;
          }
        }
        .info-price {
          display: flex;
          align-items: flex-end;
          flex-direction: row;
          justify-content: space-between;
          p {
            font-size: 82px;
            font-weight: 700;
            color: #fb463f;
          }
        }
      }
    }
  }
  .check-more {
    width: 768px;
    height: 154px;
    background: #d71519;
    margin: 102px auto 0;
    display: flex;
    align-items: center;
    justify-content: center;
    span {
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 61px;
      color: #fff;
    }
    img {
      width: 31px;
      height: 51px;
      margin-left: 10px;
    }
  }
}
</style>
